import { BaseWindow } from "../../../../component/window/BaseWindow";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { GameProxy } from "../../../mvc/GameProxy";
import { Cache } from "../../../cache/Cache";
import { AutoFight } from "../../autoFight/AutoFight";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ECopyWaitingOperate } from "../../../../../Message/Public/ECopyWaitingOperate";
import { ObjCreate } from "../../common/ObjCreate";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PageItemRenderer } from "../../common/renderers/PageItemRenderer";
import { GroupPlayerCellRenderer } from "../GroupPlayerCellRenderer";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { GlobalSkin } from "../../../../component/skin/GlobalSkin";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class Lv88TeamEnterWin
    
    export  class Lv88TeamEnterWin extends BaseWindow
    {
        constructor(arg1: TCopy, arg2: ILayer=null)
        {
            super(arg2);
            this._info = arg1;
            this._rewardCodes = arg1.reward.split(",");
            this.setSize(583, 440);
            this.title = Language.getString(80605) + Language.getString(33036);
            this.titleHeight = 27;
            this._btnCreateTeam.addEventListener(flash.events.MouseEvent.CLICK, this.createTeamHandler);
            this._btnEnterCopy.addEventListener(flash.events.MouseEvent.CLICK, this.enterCopyHandler);
            this._btnGather.addEventListener(flash.events.MouseEvent.CLICK, this.gatherTeamHandler);
            this._btnInvite.addEventListener(flash.events.MouseEvent.CLICK, this.inviteHandler);
            return;
        }

        public get copyInfo(): TCopy
        {
            return this._info;
        }

        public updateGroupMemberList(arg1: DataProvider, arg2: Boolean): void
        {
            if (arg1.length != 0) 
            {
                this._groupMember.dataProvider = arg1;
                this._groupMember.drawNow();
                this._groupMember.visible = true;
                this._bmpTeamMsg.visible = false;
                this._btnGather.visible = true;
                this._btnInvite.visible = true;
                DisplayUtil.setEnabled(this._btnCreateTeam, false);
                if (arg2) 
                {
                    DisplayUtil.setEnabled(this._btnEnterCopy, true);
                    DisplayUtil.setEnabled(this._btnGather, true);
                    if (arg1.length < 5) 
                    {
                        DisplayUtil.setEnabled(this._btnInvite, true);
                    }
                    else 
                    {
                        DisplayUtil.setEnabled(this._btnInvite, false);
                    }
                }
                else 
                {
                    DisplayUtil.setEnabled(this._btnEnterCopy, false);
                    DisplayUtil.setEnabled(this._btnGather, false);
                    DisplayUtil.setEnabled(this._btnInvite, false);
                }
            }
            else 
            {
                this._groupMember.visible = false;
                this._btnGather.visible = false;
                this._btnInvite.visible = false;
                this._bmpTeamMsg.visible = true;
                DisplayUtil.setEnabled(this._btnCreateTeam, true);
                DisplayUtil.setEnabled(this._btnEnterCopy, false);
            }
            return;
        }

        /* internal  */createTeamHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            GameProxy.groupProxy.createGroup(Cache.instance.group.memberInvite, AutoFight.localAutoFight.acceptTeam);
            return;
        }

        /* internal  */enterCopyHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.pack.backPackCache.getItemByCode(14168001) == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80607));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupDoEnterCopy, this._info.code));
            return;
        }

        /* internal  */gatherTeamHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            MsgManager.showRollTipsMsg(Language.getString(60014));
            GameProxy.copy.enterCopyWaitingRoom_async(this._info.code, ECopyWaitingOperate._ECopyWaitingGather, 3000107);
            return;
        }

        /* internal  */inviteHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            MsgManager.showRollTipsMsg(Language.getString(60013));
            GameProxy.copy.enterCopyWaitingRoom_async(this._info.code, ECopyWaitingOperate._ECopyWaitingInvite, 3000107);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 39, 546, 122, this);
            var loc1=ObjCreate.createBitmap(null, 18, 40, this);
            LoaderHelp.setBitmapdata(ImagesConst.lv88Team_bg + ".swf", loc1);
            ObjCreate.createBg(17, 162, 546, 264, this);
            var loc2=GlobalStyle.textFormat1;
            loc2.color = 65280;
            loc2.leading = 9;
            var loc3=ObjCreate.createGTextField("", 142, 180, 400, 60, this, loc2);
            loc3.multiline = true;
            loc3.wordWrap = true;
            loc3.htmlText = Language.getString(80606);
            this._list = ObjCreate.createTileList(145, 229, 400, 45, this);
            this._list.setStyle("cellRenderer", PageItemRenderer);
            this._list.columnWidth = 50;
            this._list.rowHeight = 40;
            var loc4=new DataProvider();
            var loc5=0;
            while (loc5 < this._rewardCodes.length) 
            {
                if (int(this._rewardCodes[loc5]) != 0) 
                {
                    loc4.addItem(int(this._rewardCodes[loc5]));
                }
                ++loc5;
            }
            this._list.dataProvider = loc4;
            this._list.drawNow();
            ObjCreate.createFlowerBg(22, 273, 534, 109, this);
            this._bmpTeamMsg = ObjCreate.createBitmap(null, 240, 319, this);
            this._groupMember = ObjCreate.createTileList(57, 272, 480, 120, this);
            this._groupMember.setStyle("cellRenderer", GroupPlayerCellRenderer);
            this._groupMember.scrollPolicy = ScrollPolicy.OFF;
            this._groupMember.columnWidth = 237;
            this._groupMember.rowHeight = 34;
            this._btnInvite = ObjCreate.createGButton(Language.getString(60008), 324, 350, 65, 25, this);
            this._btnGather = ObjCreate.createGButton(Language.getString(60010), 414, 350, 65, 25, this);
            this._btnCreateTeam = ObjCreate.createGButton(Language.getString(62010), 189, 391, 77, 26, this, GlobalSkin.ButtonRed);
            this._btnEnterCopy = ObjCreate.createGButton(Language.getString(60665), 317, 391, 77, 26, this, GlobalSkin.ButtonRed);
            LoaderHelp.addResCallBack(ResFileConst.lv88Team, this.onResGot);
            return;
        }

        /* internal  */onResGot(): void
        {
            ObjCreate.createBitmap(ImagesConst.Lv88Team_tips, 50, 60, this);
            ObjCreate.createBitmap(ImagesConst.Lv88Team_Challenge, 28, 178, this);
            ObjCreate.createBitmap(ImagesConst.Lv88Team_Drop, 28, 236, this);
            this._bmpTeamMsg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Lv88Team_TeamInfo);
            return;
        }

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_rewardCodes: Array<any>;

        /* internal */ /* var */_bmpTeamMsg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnCreateTeam: GButton;

        /* internal */ /* var */_btnEnterCopy: GButton;

        /* internal */ /* var */_groupMember: GTileList;

        /* internal */ /* var */_btnGather: GButton;

        /* internal */ /* var */_btnInvite: GButton;

        /* internal */ /* var */_info: TCopy;
    }
